<template>
	<view class="content">
		<!-- #ifdef H5 || APP-PLUS -->
		<view class="message-title">
			<commonTitleNear title="熊猫优选"></commonTitleNear>
		</view>
		<!-- #endif -->
		<scroll-view  scroll-y="true" class="scroll-Y scroll-box">
			
			<view  class="scroll-view-item item-share"
			v-if="list.length>0"
			v-for="(item,index) in list" :key="index"
			>
				<!-- 分享源 -->
				<view class="share-user">
					<image src="../../static/common/share-user-img.png" class="share-user-img"></image>
					<view class="share-user-info">
						<view class="user-type">选品人：超级管理员</view>
						<view class="share-time">{{getTime(item.publishTime.time)}}</view>
					</view>
					<image src="../../static/common/share-btn.png" class="share-btn" @tap="shareGoods(index)"></image>
					
				</view>
				<!-- 分享box -->
				<shareBox :itemList="item.itemList" :content="item.content" @goodDetail="goodDetail"></shareBox>
				
				<!-- 专题页 -->
				<view class="special-page">
						<image src="../../static/common/special-page-btn.png" class="special-page-btn"
						@tap="goSpecial(item.title,item.itemList)"
						></image>
					
				</view>
			</view>
			
			
		</scroll-view>
	</view>
	
</template>

<script>
	import commonTitleNear from'../../components/titile-near/title.vue'
	import shareBox  from'../../components/share/share-box.vue'
	export default{
		data(){
			return{
				apptoken:"",
				list:"",
				pageIndex:1,
				nodata:false,
				idList:[]
			}
		},
		onLoad() {
			this.apptoken = uni.getStorageSync("apptoken");
			this.getgoodsRecommend();
		},
		components:{
			commonTitleNear,
			shareBox
		},
		methods:{
			shareGoods(index){
				if(!this.apptoken){
					uni.navigateTo({
						url:'../login/login',
						animationType:'slide-in-bottom',
					})
					return;
				}
				//一键分享
				console.log(index);
				const str = this.idList[index].join(",");
				uni.navigateTo({
					url:'./oneKeyShare?str='+str
				})
			},
			goSpecial(title,item){
				//查看专题
				const _this = this;
				uni.setStorage({
					key:"special",
					data:item,
					success() {
						_this.$CommonJS.navigateTo("./special?title="+title);
					}
				})
				
			},
			goodDetail(id){
				//商品详情
				const _this = this;
				_this.$CommonJS.navigateTo('../goodDetail/good-detail?id='+id);
				// uni.request({
				// 	url:this.$API.URL + this.$API.tbk_tk_qrcode,
				// 	data:{apptoken:this.apptoken,goodsId:id},
				// 	success(res) {
				// 		console.log(res)
				// 	}
				// })
			},
			getTime(time){//时间戳处理
			  return	this.$CommonJS.getTime(time);
			},
			getgoodsRecommend(type){
				//获取列表
				const _this = this;
				if(!this.nodata){
					uni.request({
						url:this.$API.URL + this.$API.goodsRecommend,
						data:{pageIndex:this.pageIndex},
						success(res) {
							console.log(res);
							if(res.data.success){
								if(res.data.data.length<1){
									_this.nodata = true;
									_this.$CommonJS.showToast("没有更多数据了");
								}else{
									_this.pageIndex = _this.pageIndex + 1;
									if(type=="loadmore"){
										_this.list.push(res.data.data);
										
									}else{
										//_this.idList = [];
										_this.list = res.data.data;
									}
									const idlist =[];
									res.data.data.forEach(current=>{
										current.itemList.forEach(item=>{
											idlist.push(item.goodsId);
										})
										_this.idList.push(idlist);
									})
								
									console.log( _this.idList)
								}
							}else{
								_this.$CommonJS.showToast(res.data.msg);
							}
						}
					})
				}
				
			}
		}
	}
</script>

<style>
	@import url("optimization.css");
	.share-box{
		width: calc(100% - 100upx);
		height: auto;
		padding: 0 50upx;
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		align-items: center;
	}
	.share-text{
		width: 100%;
		font-size:14px;
		font-family:Alibaba PuHuiTi;
		font-weight:400;
		line-height:40upx;
		color:rgba(17,23,57,1);
		opacity:1;
	}
	.share-goods{
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		flex-wrap: wrap;
		margin-top: 34upx;
		margin-bottom: 29upx;
	}
	.goods-block{
		width:214upx;
		height:214upx;
		background:rgba(240,243,247,1);
		opacity:1;
		position: relative;
		margin-right: 4upx;
		margin-bottom: 4upx;
	}
	.goods-block:nth-child(3n){
		margin:0;
	}
	.goods-img{
		width:214upx;
		height:214upx;
	}
	.goods-price{
		position: absolute;
		right: 0;
		bottom: 0;
		width: 130upx;
		height: 50upx;
		text-align: center;
		line-height: 50upx;
		font-size: 14px;
		color: #FFFFFF;
		background: red;
	}
</style>
